package com.atguigu.algorithm;

public class TheMaxDifferBetweenLeftAndRight {
    public static int findMaxGap(int[] A,int n){
        int leftMax=A[0];
        int maxDiff=Integer.MIN_VALUE;
        for(int i=0;i<n;i++){
            if(A[i]>leftMax){
                leftMax=A[i];
            }
            int rightMax=A[n-1];//初始值
            for(int j=n-1;j>i;j--){
                if(A[j]>rightMax){
                    rightMax=A[j];
                }
            }
            int diff=Math.abs(leftMax-rightMax);
            if(diff>maxDiff){
                maxDiff=diff;
            }
        }
        return maxDiff;
    }
}
